package com.example.demo.mapper;

import com.example.demo.entity.Follow;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 关注表 Mapper 接口
 * </p>
 *
 * @author Mr.we
 * @since 2024-06-04
 */
@Mapper
public interface FollowMapper extends BaseMapper<Follow> {
    //添加
    @Insert("insert into follow(follow_user_id,followed_user_id,create_time) values(#{followUserId},#{followedUserId},NOW())")
    int insertFollow(Follow follow);

    /**
     * 根据用户id查询所有关注
     * @param userId
     * @return
     */
    @Select("select * from follow WHERE follow_user_id = #{userId}")
    List<Follow> findFollowByUserId(Integer userId);

    /**
     * 根据用户id查询所有粉丝
     * @param userId
     * @return
     */
    @Select("select * from follow WHERE followed_user_id = #{userId}")
    List<Follow> findFollowedByUserId(Integer userId);

    /**
     * 取消关注
     * @param follow
     * @return
     */
    @Delete("delete from follow where follow_user_id = #{followUserId} and followed_user_id = #{followedUserId}")
    int cancelFollow(Follow follow);

    @Select("select * from follow where follow_user_id = #{followUserId} and followed_user_id = #{followedUserId}")
    Follow findFollow(Follow follow);
}
